package com.seal.commons.config.apollo.autoConfigure;

import com.seal.commons.config.apollo.configuration.ApolloProperties;
import com.seal.commons.config.apollo.endpoint.ApolloConfigEndpoint;
import com.seal.commons.config.apollo.locator.ApolloPropertySourceExtractor;
import com.seal.commons.config.apollo.refresh.ApolloConfigRefreshHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName:ApolloConfigEndpointAutoConfiguration <br/>
 * Funct: endpoint. <br/>
 * Date:     2019-05-22 09:36 <br/>
 *
 * @author yong.huang
 * @see
 * @since JDK 1.8
 */

@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass(value = Endpoint.class)
public class ApolloConfigEndpointAutoConfiguration {

    @Autowired
    private ApolloProperties apolloProperties;

    @Autowired
    private ApolloConfigRefreshHistory refreshHistory;

    @ConditionalOnMissingBean
    @Bean
    public ApolloConfigEndpoint apolloConfigEndpoint(ApolloPropertySourceExtractor apolloPropertySourceExtractor) {
        return new ApolloConfigEndpoint(apolloProperties, refreshHistory, apolloPropertySourceExtractor);
    }
}
